package xmlS
{
	import main.XMLLoaderBase;
	
	import struct.Restaurant;
	import struct.ScenicShop;
	
	public class ScenicShopXMLLoader extends XMLLoaderBase
	{
		private var xmlData:XML;
		
		private var delayFuction:Function;
		private var objectList:Array = [];
		
		public function ScenicShopXMLLoader()
		{
		}
		
		public function initThis(func:Function = null):void
		{
			delayFuction = func;
			loadXml(uri.getScenicShopXml("ScenicShop"),saveData,loadingThis);
		}
		
		private function saveData(data:XML = null):void
		{
			if(data){
				xmlData = data;
				changeAndSave();
			}
			
			if(delayFuction is Function){
				delayFuction();
				delayFuction = null;
			}
		}
		
		private function changeAndSave():void
		{
			objectList = [];
			
			var list:Array = changeListToArray(xmlData.shop);//xmlData.shop;
			for(var i:int = 0;i < list.length;i++){
				var obj:ScenicShopDesign = new ScenicShopDesign;
				obj.init(list[i],this.uri);
				
				var scenicStruct:ScenicShop = new ScenicShop();
				scenicStruct.initWithData(obj);
				objectList.push(scenicStruct);
			}
		}
		
		private function changeListToArray(list:XMLList):Array
		{
			var valueList:Array = [];
			
			for each(var xml:XML in list){
				valueList.push(xml);
			}
			
			return valueList;
		}
		
		private function loadingThis():void
		{
			trace("正在拉取商店配置");
		}
		
		public function get shopList():Array
		{
			return objectList;
		}
		
		public function load(keyName:*,keynum:* = null):*
		{
			var value:*;
			
			if(objectList.length == 0){
				initThis(function():void{value = load(keyName,keynum)});
			}else{
				value = getValue(keyName,keynum);
			}
			
			return value;
		}
	
		private function getValue(keyName:*,keyNum:* = null):*
		{
			var info:Object;
			
			if(keyNum != null){
				for(var i:int = 0;i < objectList.length;i++){
					if(objectList[i][keyName] && objectList[i][keyName] == keyNum){
						info = objectList[i]
						return info;
					}
				}
				return null;
			}else{
				return objectList;
			}
		}
	}
}
import assists.URI;

import main.ClientConstants;

class ScenicShopDesign
{
	public var id:int = 0;
	public var type:int = ClientConstants.VISIT_TYPE_FUN;
	public var name:String;
	public var starLevel:int;
	public var location:Array;
	public var desc:String = "";
	public var url:String = "";
	public var costNum:int = 0;
	public var picList:Array = [];
	public var time:String = "";
	public var address:String = "";
	public var phone:String = "";
	public var traffic:String = "";
	public var aroundList:Array = [];
	public var website:String = "";
	
	public function init(xml:XML,uri:URI):void
	{
		this.id = xml.id;
		this.type = xml.type;
		this.name = xml.name;
		this.starLevel = xml.starLevel;
		this.location = String(xml.location).split("^");
		this.desc = xml.desc;
		if(String(xml.url) == "")
		{
			this.url = "";
		}else
		{
			this.url = uri.getScenicShop("scenicShop/",xml.url);
		}
		this.costNum = xml.costNum;
		this.picList = String(xml.pic).split(",");
		this.time = xml.time;
		this.address = xml.address;
		this.phone = xml.phone;
		this.traffic = xml.traffic;
		this.aroundList = String(xml.around).split(",");
		this.website = xml.website;
	}
}